#!/bin/bash
#
#   This file is part of poat.
#
#   poat is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   poat is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with poat.  If not, see <http://www.gnu.org/licenses/>.
#

export TMP="/home/poat/tmp/pofiles"
export LANG="en_US"
export POFILE=$1

if `msgfmt --check-header $POFILE >& /dev/null`
then
	msgfmt --statistics $POFILE >& $TMP/filestats
	POTRANS=`cat  $TMP/filestats | gawk -F, '{print $1}' | sed 's/ translated messages//'` 

	if `echo $POTRANS | grep \. >/dev/null`
	then
		POTRANS=`echo $POTRANS| sed 's/\.//'`
	fi

	if `echo $POTRANS | grep "translated message" >/dev/null`
	then
		POTRANS=`echo $POTRANS| sed 's/ translated message//'`
	fi

	if [ "$POTRANS" == "" ]
	then
		POTRANS="0"
	fi
		
	#in stats are fuzzy skipped, if they are 0 
	if `cat $TMP/filestats | grep fuzzy >/dev/null`
	then
		POFUZZY=`cat  $TMP/filestats|  gawk -F, '{print $2}' | sed 's/ fuzzy translations//' | sed 's/ //'`

		if `echo $POFUZZY | grep "fuzzy translation" >/dev/null`
		then
			POFUZZY=`echo $POFUZZY| sed 's/ fuzzy translation//'`
		fi

		if `echo $POFUZZY | grep \. >/dev/null`
		then
			POFUZZY=`echo $POFUZZY| sed 's/\.//'`
		fi

		if [ "$POFUZZY" == "" ]
		then
			POFUZZY="0"
		fi
				
		POUN=`cat  $TMP/filestats|  gawk -F, '{print $3}' | sed 's/ untranslated messages\.//' | sed 's/ //'`

		if `echo $POUN | grep "untranslated message" >/dev/null`
		then
			POUN=`echo $POUN| sed 's/ untranslated message.//'`
		fi

		if [ "$POUN" == "" ]
		then
			POUN="0"
		fi
	else
		POFUZZY="0"
		POUN=`cat  $TMP/filestats|  gawk -F, '{print $2}' | sed 's/ untranslated messages\.//' | sed 's/ //'`
	
		if `echo $POUN | grep "untranslated message" >/dev/null`
		then
			POUN=`echo $POUN| sed 's/ untranslated message.//'`
		fi

		if [ "$POUN" == "" ]
		then
			POUN="0"
		fi
	fi
	echo $POTRANS';'$POUN';'$POFUZZY
fi	
rm $TMP/filestats
